

#import "MBProgressHUD+Ex.h"

@implementation MBProgressHUD (Ex)


/**
 *  显示信息
 *
 *  @param text 信息内容
 *  @param icon 显示图标
 *  @param view 显示信息的视图
 */
+ (void)showText:(NSString *)text icon:(NSString *)icon view:(UIView *)view{
    //判断视图是否为空
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    //快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    //设置显示信息
    hud.labelText = text;
    //设置显示图标
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    //设置模式
    hud.mode = MBProgressHUDModeCustomView;
    //隐藏的时候移除
    hud.removeFromSuperViewOnHide = YES;
    //设置一秒之后隐藏
    [hud hide:YES afterDelay:1];
    
}

+ (void)showFlower:(NSString *)flower toView:(UIView *)view{
    [self showText:flower icon:@"花.png@2x.png" view:view];
}

+ (void)showFlower:(NSString *)flower{
    [self showFlower:flower toView:nil];
}


/**
 *  显示成功信息
 *
 *  @param success 成功信息内容
 *  @param view    显示成功信息的视图
 */
+ (void)showSuccess:(NSString *)success toView:(UIView *)view{
    [self showText:success icon:@"success.png" view:view];
}
/**
 *  显示失败信息
 *
 *  @param error 失败信息内容
 *  @param view  显示失败信息的视图
 */
+ (void)showError:(NSString *)error toView:(UIView *)view{
    [self showText:error icon:@"error.png" view:view];
}
/**
 *  显示成功信息
 *
 *  @param success 成功信息的内容
 */
+ (void)showSuccess:(NSString *)success{
    [self showSuccess:success toView:nil];
}
/**
 *  显示失败信息
 *
 *  @param error 失败信息的内容
 */
+ (void)showError:(NSString *)error{
    [self showError:error toView:nil];
}
/**
 *  显示一些信息
 *
 *  @param message 信息内容
 *  @param view    显示信息的视图
 *
 *  @return 返回当前实例对象 需要手动关闭
 */
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view{
    //判断视图是否为空
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    //创建提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    //设置信息内容
    hud.labelText = message;
    //隐藏的时候移除
    hud.removeFromSuperViewOnHide = YES;
    //设置蒙版效果
    hud.dimBackground = YES;
    //返回
    return hud;
}
/**
 *  显示一些信息
 *
 *  @param message 信息内容
 *
 *  @return 返回当前实例对象 需要手动关闭
 */
+ (MBProgressHUD *)showMessage:(NSString *)message{
    return [self showMessage:message toView:nil];
}
/**
 *  手动关闭MBProgressHUD
 *
 *  @param view 显示MBProgressHUD的视图
 */
+ (void)hideHUDForView:(UIView *)view{
    if (view == nil) {
        view = [[UIApplication sharedApplication].windows lastObject];
    }
    //关闭MBProgressHUD
    [self hideHUDForView:view animated:YES];
}
/**
 *  手动关闭MBProgressHUD
 */
+ (void)hideHUD{
    [self hideHUDForView:nil];
}











@end
